package com.example.nonggo.view.act;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.Glide;
import com.example.nonggo.Constants;
import com.example.nonggo.base.BaseMvpActivity;
import com.example.nonggo.contract.WeatherContract;
import com.example.nonggo.databinding.ActivityWeatherBinding;
import com.example.nonggo.model.WeatherModel;
import com.example.nonggo.presenter.WeatherPresenter;
import com.tencent.mmkv.MMKV;

public class WeatherActivity extends BaseMvpActivity<WeatherContract, WeatherPresenter, ActivityWeatherBinding> implements WeatherContract {


    @Override
    protected void initData() {
        presenter.getConditionData(MMKV.defaultMMKV().getString(Constants.PROVINCE, "广东省"),
                MMKV.defaultMMKV().getString(Constants.CITY, "广州市"),
                MMKV.defaultMMKV().getString(Constants.COUNTY, "天河区"));
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected void initListener() {
        getBinding().btnAiWeatherHandle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(WeatherActivity.this, AiWeatherActivity.class);
                startActivity(intent);
            }
        });
        getBinding().btnWeatherData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(WeatherActivity.this, WeatherDetailActivity.class);
                startActivity(intent);
            }
        });

    }


    @Override
    protected WeatherPresenter createPresenter() {
        return new WeatherPresenter(new WeatherModel());
    }

    @Override
    protected ActivityWeatherBinding getViewBinding() {
        return ActivityWeatherBinding.inflate(getLayoutInflater());
    }

    @Override
    public void getConditionSuccess(String temp, String condition, String icon) {
        String tvText = temp + "℃";
        getBinding().tvWeather.setText(condition);
        getBinding().tvTemp.setText(tvText);
        getBinding().ivArea.setText(MMKV.defaultMMKV().getString(Constants.FULL_NAME,"广东省-广州市-天河区"));
//        getBinding().btnLocation.setText(MMKV.defaultMMKV().getString(Constants.FULL_NAME, ""));
        Glide.with(this).load(icon).into(getBinding().ivWeather);
    }
    // 添加窗口焦点变化监听
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}
